package com.smooth.dao.gen;

import com.smooth.dao.gen.bean.BizCompany;
import com.smooth.dao.gen.bean.BizCompanyExample.Criteria;
import com.smooth.dao.gen.bean.BizCompanyExample.Criterion;
import com.smooth.dao.gen.bean.BizCompanyExample;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.jdbc.SQL;

public class BizCompanySqlProvider {
    /** biz_company */
    public String countByExample(BizCompanyExample example) {
        SQL sql = new SQL();
        sql.SELECT("count(*)").FROM("biz_company");
        applyWhere(sql, example, false);
        return sql.toString();
    }

    /** biz_company */
    public String deleteByExample(BizCompanyExample example) {
        SQL sql = new SQL();
        sql.DELETE_FROM("biz_company");
        applyWhere(sql, example, false);
        return sql.toString();
    }

    /** biz_company */
    public String insertSelective(BizCompany record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("biz_company");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=VARCHAR}");
        }
        
        if (record.getAccountNo() != null) {
            sql.VALUES("account_no", "#{accountNo,jdbcType=VARCHAR}");
        }
        
        if (record.getCompName() != null) {
            sql.VALUES("comp_name", "#{compName,jdbcType=VARCHAR}");
        }
        
        if (record.getScale() != null) {
            sql.VALUES("scale", "#{scale,jdbcType=INTEGER}");
        }
        
        if (record.getNature() != null) {
            sql.VALUES("nature", "#{nature,jdbcType=INTEGER}");
        }
        
        if (record.getCompPic() != null) {
            sql.VALUES("comp_pic", "#{compPic,jdbcType=VARCHAR}");
        }
        
        if (record.getCompPics() != null) {
            sql.VALUES("comp_pics", "#{compPics,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getJobCount() != null) {
            sql.VALUES("job_count", "#{jobCount,jdbcType=INTEGER}");
        }
        
        if (record.getJobAll() != null) {
            sql.VALUES("job_all", "#{jobAll,jdbcType=INTEGER}");
        }
        
        if (record.getJobShengyu() != null) {
            sql.VALUES("job_shengyu", "#{jobShengyu,jdbcType=INTEGER}");
        }
        
        if (record.getJobFlag() != null) {
            sql.VALUES("job_flag", "#{jobFlag,jdbcType=SMALLINT}");
        }
        
        if (record.getZhusuPics() != null) {
            sql.VALUES("zhusu_pics", "#{zhusuPics,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getPercent() != null) {
            sql.VALUES("percent", "#{percent,jdbcType=DOUBLE}");
        }
        
        if (record.getCompAddress() != null) {
            sql.VALUES("comp_address", "#{compAddress,jdbcType=VARCHAR}");
        }
        
        if (record.getCompLicensePic() != null) {
            sql.VALUES("comp_license_pic", "#{compLicensePic,jdbcType=VARCHAR}");
        }
        
        if (record.getContactName() != null) {
            sql.VALUES("contact_name", "#{contactName,jdbcType=VARCHAR}");
        }
        
        if (record.getCategoryId() != null) {
            sql.VALUES("category_id", "#{categoryId,jdbcType=VARCHAR}");
        }
        
        if (record.getCategoryName() != null) {
            sql.VALUES("category_name", "#{categoryName,jdbcType=VARCHAR}");
        }
        
        if (record.getContactTelNo() != null) {
            sql.VALUES("contact_tel_no", "#{contactTelNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPassword() != null) {
            sql.VALUES("password", "#{password,jdbcType=VARCHAR}");
        }
        
        if (record.getContactJob() != null) {
            sql.VALUES("contact_job", "#{contactJob,jdbcType=VARCHAR}");
        }
        
        if (record.getProvinceId() != null) {
            sql.VALUES("province_id", "#{provinceId,jdbcType=VARCHAR}");
        }
        
        if (record.getProvinceName() != null) {
            sql.VALUES("province_name", "#{provinceName,jdbcType=VARCHAR}");
        }
        
        if (record.getCityId() != null) {
            sql.VALUES("city_id", "#{cityId,jdbcType=VARCHAR}");
        }
        
        if (record.getCityName() != null) {
            sql.VALUES("city_name", "#{cityName,jdbcType=VARCHAR}");
        }
        
        if (record.getAreaId() != null) {
            sql.VALUES("area_id", "#{areaId,jdbcType=VARCHAR}");
        }
        
        if (record.getAreaName() != null) {
            sql.VALUES("area_name", "#{areaName,jdbcType=VARCHAR}");
        }
        
        if (record.getDetail() != null) {
            sql.VALUES("detail", "#{detail,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getJiabanType() != null) {
            sql.VALUES("jiaban_type", "#{jiabanType,jdbcType=SMALLINT}");
        }
        
        if (record.getJiabanFee() != null) {
            sql.VALUES("jiaban_fee", "#{jiabanFee,jdbcType=SMALLINT}");
        }
        
        if (record.getJobTime() != null) {
            sql.VALUES("job_time", "#{jobTime,jdbcType=SMALLINT}");
        }
        
        if (record.getCreateDate() != null) {
            sql.VALUES("create_date", "#{createDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateDate() != null) {
            sql.VALUES("update_date", "#{updateDate,jdbcType=TIMESTAMP}");
        }
        
        return sql.toString();
    }

    /** biz_company */
    public String selectByExample(BizCompanyExample example) {
        SQL sql = new SQL();
        if (example != null && example.isDistinct()) {
            sql.SELECT_DISTINCT("id");
        } else {
            sql.SELECT("id");
        }
        sql.SELECT("account_no");
        sql.SELECT("comp_name");
        sql.SELECT("scale");
        sql.SELECT("nature");
        sql.SELECT("comp_pic");
        sql.SELECT("comp_pics");
        sql.SELECT("job_count");
        sql.SELECT("job_all");
        sql.SELECT("job_shengyu");
        sql.SELECT("job_flag");
        sql.SELECT("zhusu_pics");
        sql.SELECT("percent");
        sql.SELECT("comp_address");
        sql.SELECT("comp_license_pic");
        sql.SELECT("contact_name");
        sql.SELECT("category_id");
        sql.SELECT("category_name");
        sql.SELECT("contact_tel_no");
        sql.SELECT("password");
        sql.SELECT("contact_job");
        sql.SELECT("province_id");
        sql.SELECT("province_name");
        sql.SELECT("city_id");
        sql.SELECT("city_name");
        sql.SELECT("area_id");
        sql.SELECT("area_name");
        sql.SELECT("detail");
        sql.SELECT("jiaban_type");
        sql.SELECT("jiaban_fee");
        sql.SELECT("job_time");
        sql.SELECT("create_date");
        sql.SELECT("update_date");
        sql.FROM("biz_company");
        applyWhere(sql, example, false);
        
        if (example != null && example.getOrderByClause() != null) {
            sql.ORDER_BY(example.getOrderByClause());
        }
        
        return sql.toString();
    }

    /** biz_company */
    public String updateByExampleSelective(Map<String, Object> parameter) {
        BizCompany record = (BizCompany) parameter.get("record");
        BizCompanyExample example = (BizCompanyExample) parameter.get("example");
        
        SQL sql = new SQL();
        sql.UPDATE("biz_company");
        
        if (record.getId() != null) {
            sql.SET("id = #{record.id,jdbcType=VARCHAR}");
        }
        
        if (record.getAccountNo() != null) {
            sql.SET("account_no = #{record.accountNo,jdbcType=VARCHAR}");
        }
        
        if (record.getCompName() != null) {
            sql.SET("comp_name = #{record.compName,jdbcType=VARCHAR}");
        }
        
        if (record.getScale() != null) {
            sql.SET("scale = #{record.scale,jdbcType=INTEGER}");
        }
        
        if (record.getNature() != null) {
            sql.SET("nature = #{record.nature,jdbcType=INTEGER}");
        }
        
        if (record.getCompPic() != null) {
            sql.SET("comp_pic = #{record.compPic,jdbcType=VARCHAR}");
        }
        
        if (record.getCompPics() != null) {
            sql.SET("comp_pics = #{record.compPics,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getJobCount() != null) {
            sql.SET("job_count = #{record.jobCount,jdbcType=INTEGER}");
        }
        
        if (record.getJobAll() != null) {
            sql.SET("job_all = #{record.jobAll,jdbcType=INTEGER}");
        }
        
        if (record.getJobShengyu() != null) {
            sql.SET("job_shengyu = #{record.jobShengyu,jdbcType=INTEGER}");
        }
        
        if (record.getJobFlag() != null) {
            sql.SET("job_flag = #{record.jobFlag,jdbcType=SMALLINT}");
        }
        
        if (record.getZhusuPics() != null) {
            sql.SET("zhusu_pics = #{record.zhusuPics,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getPercent() != null) {
            sql.SET("percent = #{record.percent,jdbcType=DOUBLE}");
        }
        
        if (record.getCompAddress() != null) {
            sql.SET("comp_address = #{record.compAddress,jdbcType=VARCHAR}");
        }
        
        if (record.getCompLicensePic() != null) {
            sql.SET("comp_license_pic = #{record.compLicensePic,jdbcType=VARCHAR}");
        }
        
        if (record.getContactName() != null) {
            sql.SET("contact_name = #{record.contactName,jdbcType=VARCHAR}");
        }
        
        if (record.getCategoryId() != null) {
            sql.SET("category_id = #{record.categoryId,jdbcType=VARCHAR}");
        }
        
        if (record.getCategoryName() != null) {
            sql.SET("category_name = #{record.categoryName,jdbcType=VARCHAR}");
        }
        
        if (record.getContactTelNo() != null) {
            sql.SET("contact_tel_no = #{record.contactTelNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPassword() != null) {
            sql.SET("password = #{record.password,jdbcType=VARCHAR}");
        }
        
        if (record.getContactJob() != null) {
            sql.SET("contact_job = #{record.contactJob,jdbcType=VARCHAR}");
        }
        
        if (record.getProvinceId() != null) {
            sql.SET("province_id = #{record.provinceId,jdbcType=VARCHAR}");
        }
        
        if (record.getProvinceName() != null) {
            sql.SET("province_name = #{record.provinceName,jdbcType=VARCHAR}");
        }
        
        if (record.getCityId() != null) {
            sql.SET("city_id = #{record.cityId,jdbcType=VARCHAR}");
        }
        
        if (record.getCityName() != null) {
            sql.SET("city_name = #{record.cityName,jdbcType=VARCHAR}");
        }
        
        if (record.getAreaId() != null) {
            sql.SET("area_id = #{record.areaId,jdbcType=VARCHAR}");
        }
        
        if (record.getAreaName() != null) {
            sql.SET("area_name = #{record.areaName,jdbcType=VARCHAR}");
        }
        
        if (record.getDetail() != null) {
            sql.SET("detail = #{record.detail,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getJiabanType() != null) {
            sql.SET("jiaban_type = #{record.jiabanType,jdbcType=SMALLINT}");
        }
        
        if (record.getJiabanFee() != null) {
            sql.SET("jiaban_fee = #{record.jiabanFee,jdbcType=SMALLINT}");
        }
        
        if (record.getJobTime() != null) {
            sql.SET("job_time = #{record.jobTime,jdbcType=SMALLINT}");
        }
        
        if (record.getCreateDate() != null) {
            sql.SET("create_date = #{record.createDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateDate() != null) {
            sql.SET("update_date = #{record.updateDate,jdbcType=TIMESTAMP}");
        }
        
        applyWhere(sql, example, true);
        return sql.toString();
    }

    /** biz_company */
    public String updateByExample(Map<String, Object> parameter) {
        SQL sql = new SQL();
        sql.UPDATE("biz_company");
        
        sql.SET("id = #{record.id,jdbcType=VARCHAR}");
        sql.SET("account_no = #{record.accountNo,jdbcType=VARCHAR}");
        sql.SET("comp_name = #{record.compName,jdbcType=VARCHAR}");
        sql.SET("scale = #{record.scale,jdbcType=INTEGER}");
        sql.SET("nature = #{record.nature,jdbcType=INTEGER}");
        sql.SET("comp_pic = #{record.compPic,jdbcType=VARCHAR}");
        sql.SET("comp_pics = #{record.compPics,jdbcType=LONGVARCHAR}");
        sql.SET("job_count = #{record.jobCount,jdbcType=INTEGER}");
        sql.SET("job_all = #{record.jobAll,jdbcType=INTEGER}");
        sql.SET("job_shengyu = #{record.jobShengyu,jdbcType=INTEGER}");
        sql.SET("job_flag = #{record.jobFlag,jdbcType=SMALLINT}");
        sql.SET("zhusu_pics = #{record.zhusuPics,jdbcType=LONGVARCHAR}");
        sql.SET("percent = #{record.percent,jdbcType=DOUBLE}");
        sql.SET("comp_address = #{record.compAddress,jdbcType=VARCHAR}");
        sql.SET("comp_license_pic = #{record.compLicensePic,jdbcType=VARCHAR}");
        sql.SET("contact_name = #{record.contactName,jdbcType=VARCHAR}");
        sql.SET("category_id = #{record.categoryId,jdbcType=VARCHAR}");
        sql.SET("category_name = #{record.categoryName,jdbcType=VARCHAR}");
        sql.SET("contact_tel_no = #{record.contactTelNo,jdbcType=VARCHAR}");
        sql.SET("password = #{record.password,jdbcType=VARCHAR}");
        sql.SET("contact_job = #{record.contactJob,jdbcType=VARCHAR}");
        sql.SET("province_id = #{record.provinceId,jdbcType=VARCHAR}");
        sql.SET("province_name = #{record.provinceName,jdbcType=VARCHAR}");
        sql.SET("city_id = #{record.cityId,jdbcType=VARCHAR}");
        sql.SET("city_name = #{record.cityName,jdbcType=VARCHAR}");
        sql.SET("area_id = #{record.areaId,jdbcType=VARCHAR}");
        sql.SET("area_name = #{record.areaName,jdbcType=VARCHAR}");
        sql.SET("detail = #{record.detail,jdbcType=LONGVARCHAR}");
        sql.SET("jiaban_type = #{record.jiabanType,jdbcType=SMALLINT}");
        sql.SET("jiaban_fee = #{record.jiabanFee,jdbcType=SMALLINT}");
        sql.SET("job_time = #{record.jobTime,jdbcType=SMALLINT}");
        sql.SET("create_date = #{record.createDate,jdbcType=TIMESTAMP}");
        sql.SET("update_date = #{record.updateDate,jdbcType=TIMESTAMP}");
        
        BizCompanyExample example = (BizCompanyExample) parameter.get("example");
        applyWhere(sql, example, true);
        return sql.toString();
    }

    /** biz_company */
    public String updateByPrimaryKeySelective(BizCompany record) {
        SQL sql = new SQL();
        sql.UPDATE("biz_company");
        
        if (record.getAccountNo() != null) {
            sql.SET("account_no = #{accountNo,jdbcType=VARCHAR}");
        }
        
        if (record.getCompName() != null) {
            sql.SET("comp_name = #{compName,jdbcType=VARCHAR}");
        }
        
        if (record.getScale() != null) {
            sql.SET("scale = #{scale,jdbcType=INTEGER}");
        }
        
        if (record.getNature() != null) {
            sql.SET("nature = #{nature,jdbcType=INTEGER}");
        }
        
        if (record.getCompPic() != null) {
            sql.SET("comp_pic = #{compPic,jdbcType=VARCHAR}");
        }
        
        if (record.getCompPics() != null) {
            sql.SET("comp_pics = #{compPics,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getJobCount() != null) {
            sql.SET("job_count = #{jobCount,jdbcType=INTEGER}");
        }
        
        if (record.getJobAll() != null) {
            sql.SET("job_all = #{jobAll,jdbcType=INTEGER}");
        }
        
        if (record.getJobShengyu() != null) {
            sql.SET("job_shengyu = #{jobShengyu,jdbcType=INTEGER}");
        }
        
        if (record.getJobFlag() != null) {
            sql.SET("job_flag = #{jobFlag,jdbcType=SMALLINT}");
        }
        
        if (record.getZhusuPics() != null) {
            sql.SET("zhusu_pics = #{zhusuPics,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getPercent() != null) {
            sql.SET("percent = #{percent,jdbcType=DOUBLE}");
        }
        
        if (record.getCompAddress() != null) {
            sql.SET("comp_address = #{compAddress,jdbcType=VARCHAR}");
        }
        
        if (record.getCompLicensePic() != null) {
            sql.SET("comp_license_pic = #{compLicensePic,jdbcType=VARCHAR}");
        }
        
        if (record.getContactName() != null) {
            sql.SET("contact_name = #{contactName,jdbcType=VARCHAR}");
        }
        
        if (record.getCategoryId() != null) {
            sql.SET("category_id = #{categoryId,jdbcType=VARCHAR}");
        }
        
        if (record.getCategoryName() != null) {
            sql.SET("category_name = #{categoryName,jdbcType=VARCHAR}");
        }
        
        if (record.getContactTelNo() != null) {
            sql.SET("contact_tel_no = #{contactTelNo,jdbcType=VARCHAR}");
        }
        
        if (record.getPassword() != null) {
            sql.SET("password = #{password,jdbcType=VARCHAR}");
        }
        
        if (record.getContactJob() != null) {
            sql.SET("contact_job = #{contactJob,jdbcType=VARCHAR}");
        }
        
        if (record.getProvinceId() != null) {
            sql.SET("province_id = #{provinceId,jdbcType=VARCHAR}");
        }
        
        if (record.getProvinceName() != null) {
            sql.SET("province_name = #{provinceName,jdbcType=VARCHAR}");
        }
        
        if (record.getCityId() != null) {
            sql.SET("city_id = #{cityId,jdbcType=VARCHAR}");
        }
        
        if (record.getCityName() != null) {
            sql.SET("city_name = #{cityName,jdbcType=VARCHAR}");
        }
        
        if (record.getAreaId() != null) {
            sql.SET("area_id = #{areaId,jdbcType=VARCHAR}");
        }
        
        if (record.getAreaName() != null) {
            sql.SET("area_name = #{areaName,jdbcType=VARCHAR}");
        }
        
        if (record.getDetail() != null) {
            sql.SET("detail = #{detail,jdbcType=LONGVARCHAR}");
        }
        
        if (record.getJiabanType() != null) {
            sql.SET("jiaban_type = #{jiabanType,jdbcType=SMALLINT}");
        }
        
        if (record.getJiabanFee() != null) {
            sql.SET("jiaban_fee = #{jiabanFee,jdbcType=SMALLINT}");
        }
        
        if (record.getJobTime() != null) {
            sql.SET("job_time = #{jobTime,jdbcType=SMALLINT}");
        }
        
        if (record.getCreateDate() != null) {
            sql.SET("create_date = #{createDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getUpdateDate() != null) {
            sql.SET("update_date = #{updateDate,jdbcType=TIMESTAMP}");
        }
        
        sql.WHERE("id = #{id,jdbcType=VARCHAR}");
        
        return sql.toString();
    }

    /** biz_company */
    protected void applyWhere(SQL sql, BizCompanyExample example, boolean includeExamplePhrase) {
        if (example == null) {
            return;
        }
        
        String parmPhrase1;
        String parmPhrase1_th;
        String parmPhrase2;
        String parmPhrase2_th;
        String parmPhrase3;
        String parmPhrase3_th;
        if (includeExamplePhrase) {
            parmPhrase1 = "%s #{example.oredCriteria[%d].allCriteria[%d].value}";
            parmPhrase1_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
            parmPhrase2 = "%s #{example.oredCriteria[%d].allCriteria[%d].value} and #{example.oredCriteria[%d].criteria[%d].secondValue}";
            parmPhrase2_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{example.oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
            parmPhrase3 = "#{example.oredCriteria[%d].allCriteria[%d].value[%d]}";
            parmPhrase3_th = "#{example.oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
        } else {
            parmPhrase1 = "%s #{oredCriteria[%d].allCriteria[%d].value}";
            parmPhrase1_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}";
            parmPhrase2 = "%s #{oredCriteria[%d].allCriteria[%d].value} and #{oredCriteria[%d].criteria[%d].secondValue}";
            parmPhrase2_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}";
            parmPhrase3 = "#{oredCriteria[%d].allCriteria[%d].value[%d]}";
            parmPhrase3_th = "#{oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}";
        }
        
        StringBuilder sb = new StringBuilder();
        List<Criteria> oredCriteria = example.getOredCriteria();
        boolean firstCriteria = true;
        for (int i = 0; i < oredCriteria.size(); i++) {
            Criteria criteria = oredCriteria.get(i);
            if (criteria.isValid()) {
                if (firstCriteria) {
                    firstCriteria = false;
                } else {
                    sb.append(" or ");
                }
                
                sb.append('(');
                List<Criterion> criterions = criteria.getAllCriteria();
                boolean firstCriterion = true;
                for (int j = 0; j < criterions.size(); j++) {
                    Criterion criterion = criterions.get(j);
                    if (firstCriterion) {
                        firstCriterion = false;
                    } else {
                        sb.append(" and ");
                    }
                    
                    if (criterion.isNoValue()) {
                        sb.append(criterion.getCondition());
                    } else if (criterion.isSingleValue()) {
                        if (criterion.getTypeHandler() == null) {
                            sb.append(String.format(parmPhrase1, criterion.getCondition(), i, j));
                        } else {
                            sb.append(String.format(parmPhrase1_th, criterion.getCondition(), i, j,criterion.getTypeHandler()));
                        }
                    } else if (criterion.isBetweenValue()) {
                        if (criterion.getTypeHandler() == null) {
                            sb.append(String.format(parmPhrase2, criterion.getCondition(), i, j, i, j));
                        } else {
                            sb.append(String.format(parmPhrase2_th, criterion.getCondition(), i, j, criterion.getTypeHandler(), i, j, criterion.getTypeHandler()));
                        }
                    } else if (criterion.isListValue()) {
                        sb.append(criterion.getCondition());
                        sb.append(" (");
                        List<?> listItems = (List<?>) criterion.getValue();
                        boolean comma = false;
                        for (int k = 0; k < listItems.size(); k++) {
                            if (comma) {
                                sb.append(", ");
                            } else {
                                comma = true;
                            }
                            if (criterion.getTypeHandler() == null) {
                                sb.append(String.format(parmPhrase3, i, j, k));
                            } else {
                                sb.append(String.format(parmPhrase3_th, i, j, k, criterion.getTypeHandler()));
                            }
                        }
                        sb.append(')');
                    }
                }
                sb.append(')');
            }
        }
        
        if (sb.length() > 0) {
            sql.WHERE(sb.toString());
        }
    }
}